home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
simula
/
books
/
books.lha
/
kirkerud
/
filetools.sim
< prev
next >
Wrap
Text File
|
1993-08-16
|
2KB
|
60 lines
class filetools;
begin
procedure text_to_file(f, t); ref(outfile) f; text t;
begin f.outtext(t); f.outchar(separator) end;
procedure int_to_file(f, i); ref(outfile) f; integer i;
begin f.outint(i, 0); f.outchar(separator) end;
procedure real_to_file(f, r); ref(outfile) f; real r;
begin f.outreal(r, 9, 0); f.outchar(separator) end;
text procedure text_from_file(f); ref(infile) f;
if f.lastitem
then text_from_file :- notext
else begin character c; text tt, ta;
c := f.inchar; tt :- blanks(1);
while c ne separator do
begin
if not tt.more then
begin
ta :- tt; tt :- blanks(2*tt.length);
tt := ta; tt.setpos(ta.length + 1);
end;
tt.putchar(c);
if not f.more then f.inimage;
c := if f.endfile then separator else f.inchar;
end;
text_from_file :- tt.strip;
end;
integer procedure int_from_file(f); ref(infile) f;
begin text tt;
tt :- text_from_file(f);
if tt == notext then int_from_file := 0
else begin character c;
tt.setpos(1); c := tt.getchar;
if not (digit(c) or c = '-' or c = '+')
then int_from_file := 0
else begin tt.setpos(1); int_from_file := tt.getint end;
end;
end;
real procedure real_from_file(f); ref(infile) f;
begin text tt;
tt :- text_from_file(f);
if tt == notext then real_from_file := 0
else begin character c;
tt.setpos(1); c := tt.getchar;
if not (digit(c) or c = '-' or c = '+')
then real_from_file := 0
else begin tt.setpos(1); real_from_file := tt.getreal end;
end;
end;
character separator;
separator := '"';
end filetools;